<% /* $Id: submissions.jsp 96 2010-10-31 09:42:36Z altdotua@gmail.com $ */ %>

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>

<%@ include file="header.jsp" %>

<%
	if (user == null)
	{
		response.sendRedirect(
				Linker.link("login.jsp?return=" 
						+ URLEncoder.encode(request.getRequestURI(), AbstractServlet.defaultEncoding)) 
						+ "&msg="
						+ URLEncoder.encode(bundle.getString("W_NO_GUEST_ACCESS"), AbstractServlet.defaultEncoding));
		return;
	}
	HashMap <String, Object> map = new HashMap<String, Object>();
	Map<String, String> params = Misc.remap(request);
	String value;
	
	if (null != (value = params.get("page")))
		map.put("page", Long.parseLong(value));
	else
		map.put("page", 0L);
	if (null != (value = params.get("user_id")))
		map.put("userId", Long.parseLong(value));
	if (null != (value = params.get("judgement")))
		map.put("judgement", value);
	if (null != (value = params.get("problem_id")))
		map.put("contestProblemId", Long.parseLong(value));
	map.put("contestId", contest.getId());
	
	//if (!contest.getShowFullSubmissions() && !user.isAdmin())
		//map.put("userId", user.getId());
%>

<h4 align="left"><a href="<%= Linker.link("problems.jsp?contest_id=" + contest.getId()) %>"><%= contest.getName() %></a> &gt; <%= bundle.getString("W_QUEUE") %> </h4>
<table align="center" border="1" width="95%">
	<tr bgcolor="Gainsboro">
		<th>#</th>
		<th><%= bundle.getString("W_TIME") %> (GMT)</th>
		<th><%= bundle.getString("W_PROBLEM") %></th>
		<th><%= bundle.getString("W_LANGUAGE") %></th>
		<th><%= bundle.getString("W_USER") %></th>
		<th><%= bundle.getString("W_SOURCE") %></th>
		<th><%= bundle.getString("W_JUDGEMENT") %></th>
		<th><%= bundle.getString("W_SCORES") %></th>
		<th><%= bundle.getString("W_TEST") %></th>
		<th><%= bundle.getString("W_RUNTIME") %></th>
		<th><%= bundle.getString("W_MEMORY") %></th>
		<th><%= bundle.getString("W_STATE") %></th>
	</tr>
<%
	List<SubmissionEntry> entries = SubmissionsModel.getSubmissions(map);
	Map<Long, LanguageEntry> languages = LanguagesModel.getEntriesMap();
	Map<Long, ContestProblemEntry> problems = ContestProblemsModel.getEntriesMap();
	Map<Long, UserEntry> users = UsersModel.getEntriesMap();
	for (SubmissionEntry submission: entries)
	{
		String rowColor = "";
		String judgement = submission.getJudgement();
		if (submission.getDjudgeFlag() > 0)
		{
			if (judgement.equals("CE"))
			{	
				rowColor = "#cccccc";
			}
			else
			{
				if (submission.getFlagFirstTestOnly())
				{
					rowColor = "#cccccc";
				}
				else
				{
					if ("AC".equals(judgement))
						rowColor = "#aaffaa";
					else if ("WA".equals(judgement) || "TLE".equals(judgement) || "RE".equals(judgement))
						rowColor = "#ffaaaa";
					else
						rowColor = "#777777";
				}			
			}
		}
		else
		{
			rowColor = "#ffff00";
		}
		UserEntry userT = users.get(submission.getUserId());
		%>
		<tr bgcolor="<%= rowColor %>"  align="center">
			<td><%= submission.getId() %></td>
			<td><%= submission.getSubmissionTime() %></td>
			<td><a href="<%= Linker.link("problem.jsp?problem_id=" + submission.getContestProblemId()) %>"><%=problems.get(submission.getContestProblemId()) != null ? problems.get(submission.getContestProblemId()).getSid() : submission.getContestProblemId()%></a></td>
			<td><%= languages.get(submission.getLanguageId()).getSid() %></td>
			<td><%= userT == null ? submission.getUserId() : StringEscapeUtils.escapeHtml(userT.getUsername()) %></td>
			<td><a href="<%= Linker.link("source.jsp?submission_id=" + submission.getId()) %>"><%= (new PrintfFormat("%.1lf").sprintf(1.0 * submission.getSourceSize() / 1024)).replace(',', '.') %> КБ</a></td>
			<td><a href="<%= Linker.link("submission.jsp?submission_id=" + submission.getId()) %>"><%= Formatters.formatJudgement(submission.getJudgement()) %></a></td>
			<td><a href="<%= Linker.link("submission.jsp?submission_id=" + submission.getId()) %>"><%= submission.getScore() >= 0 ? submission.getScore() : "-" %></a></td>
			<td><%= submission.getWrongTestNumber() >= 0 ? submission.getWrongTestNumber() + 1 : "-" %></td>
			<td><%= submission.getMaxTimeUsed() >= 0 ? submission.getMaxTimeUsed() + " мс" : "-" %></td>
			<td><%= submission.getMaxMemoryUsed() >= 0 ? (submission.getMaxMemoryUsed() / 1024) + " КБ" : "-" %></td>
			<td><%= submission.getDjudgeFlag() == -1 ? "На перевірці" : submission.getDjudgeFlag() == 0 ? "В черзі" : "ОК" %></td>
		</tr>
		<%
	}
%>
</table>

<%= Misc.attachPager(request) %>

<%
	Long pageGenerationFinished = new Date().getTime();
%>

<!-- <%= "" + ((pageGenerationFinished - pageGenerationStarted)) + " ms" %>  -->

<%@ include file="footer.jsp" %>
